#if 0
有类定义如下：


class Car{
		private:
				string 	brand;	//品牌
				double 	price;	//价格
		public:
				void running();	//运行
};
实现该汽车类的定义，使用vector保存多个Car对象，然后按Car价格的降序排序，最后遍历vector，使每一两Car的对象运行。【4分：类的定义+初始化1分，vector的排序、遍历2分，整体+规范1分】
#endif

#include <iostream>
using namespace std;
#include <vector>
#include <algorithm>

class Car{
private:
	string	brand;
	double 	price;
public:
	Car(const string& brand, double price);
	void running();

	double getPrice() const { return this->price; }

	bool operator < (const Car& rhs) const
	{
		return this->price < rhs.price;
	}
};

Car::Car(const string& brand, double price)
	:brand(brand),
	price(price)
{

}

void Car::running() 
{
	cout << this->brand << " is runing..." << ", price is " << this->price << endl;
}


bool cmp(const Car& lhs, const Car& rhs)
{
	return lhs.getPrice() > rhs.getPrice();
}

bool cmp_pointer(const Car* lhs, const Car* rhs)
{
	return lhs->getPrice() > rhs->getPrice();
}

int main(void)
{
	vector<Car*> cars;
	Car BMW = Car("BMW", 500000);
	Car BYD = Car("BYD", 100000);
	Car BENZ = Car("BENZ", 280000);

	cars.push_back(&BMW);
	cars.push_back(&BYD);
	cars.push_back(&BENZ);

	//sort(cars.begin(), cars.end());		//必须重载<运算符
	sort(cars.begin(), cars.end(), cmp_pointer);		//必须重载<运算符
	for(vector<Car*>::iterator it = cars.begin(); it != cars.end(); ++it){
		(*it)->running();
	}
	return 0;
}

int main1(void)
{
	vector<Car> cars;
	cars.push_back(Car("BMW", 500000));
	cars.push_back(Car("BYD", 100000));
	cars.push_back(Car("BENZ", 280000));

	//sort(cars.begin(), cars.end());		//必须重载<运算符
	sort(cars.begin(), cars.end(), cmp);		//必须重载<运算符
	for(vector<Car>::iterator it = cars.begin(); it != cars.end(); ++it){
		(*it).running();
	}
	
	
	return 0;
}
